package library.and.xps.com.step.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhy.autolayout.AutoLinearLayout;

import library.and.xps.com.step.R;
import library.and.xps.com.step.m.model.Search;
import library.and.xps.com.step.util.CommonUtils;
import library.and.xps.com.step.view.activity.JoinTeamActivity;

public class SearchAdapter extends AbstractRecyclerAdapter<Search.ListBean> {
    public static final String Search_ListBean = "Search.ListBean";

    public SearchAdapter(Context context, RecyclerView recyclerView) {
        super(context, recyclerView);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        View v = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.search_item, parent, false);
        return new MyViewHolder(v);
    }

    @Override
    protected void onBindViewHolder(RecyclerView.ViewHolder holder, int position, boolean isItem) {
        MyViewHolder myViewHolder = (MyViewHolder) holder;
        final Search.ListBean data = getItem(position);
        CommonUtils.setUpimg(context, myViewHolder.iv_item_mark, data.getMark(),true);

        myViewHolder.tv_item_name.setText(data.getTname());

        myViewHolder.al_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(context, JoinTeamActivity.class);
                i.putExtra(Search_ListBean, data);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            }
        });
    }

    private static class MyViewHolder extends RecyclerView.ViewHolder {

        ImageView iv_item_mark;
        TextView tv_item_name;
        AutoLinearLayout al_item;

        MyViewHolder(View itemView) {
            super(itemView);
            iv_item_mark = (ImageView) itemView.findViewById(R.id.iv_item_mark);
            tv_item_name = (TextView) itemView.findViewById(R.id.tv_item_name);
            al_item = (AutoLinearLayout) itemView.findViewById(R.id.al_item);
        }

    }
}
